package com.example.constellation.Activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.constellation.Adapter.fg1guideadapter;
import com.example.constellation.R;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends AppCompatActivity {
    private ViewPager guidevp;
//存放三种照片
    private int[] resids={R.mipmap.loading1,R.mipmap.loading2,R.mipmap.loading3};
    private List<ImageView> imgs;
    private fg1guideadapter fg1guideadapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        guidevp=findViewById(R.id.guidevp);
        imgs=new ArrayList<>();
        initpager();
        //为三个图片设置监听事件
        setlistener();
    }

    private void setlistener() {
        int size = imgs.size();
        final ImageView imageView = imgs.get(size - 1);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(GuideActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    private void initpager() {
        for (int i=0;i<resids.length;i++){
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(resids[i]);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT);
            imageView.setLayoutParams(lp);
            imgs.add(imageView);
        }
        fg1guideadapter =new fg1guideadapter(imgs);
        guidevp.setAdapter(fg1guideadapter);
    }
}
